package net.media.datafw.transport.mvc;

import net.media.datafw.transport.Transporter;
import net.media.datafw.transport.transporters.ByteCodeTransporter;
import net.media.datafw.transport.transporters.JSONTransporter;
import net.media.datafw.transport.transporters.PListTransporter;
import net.media.datafw.transport.transporters.XMLTransporter;

public enum TransportType { 
	TRANSPORT_JSON(0, "application/x-json", new JSONTransporter()),
	TRANSPORT_XML(1, "text/xml", new XMLTransporter()),
	TRANSPORT_PLIST(2, "application/plist", new PListTransporter()), 
	TRANSPORT_BYTECODE(3, "application/octet-stream", new ByteCodeTransporter());

	private final int value;
	private final String contentType;
	private final Transporter transporter;

	private TransportType(int value, String contentType, Transporter transporter) {
		this.value = value;
		this.contentType = contentType;
		this.transporter = transporter;
	}

	public int getValue() {
		return value;
	}

	public String getContentType() {
		return contentType;
	}

	public Transporter getTransporter() {
		return transporter;
	}

	public static TransportType getTransportType(int value) {
		TransportType type = null;
		if (value == TRANSPORT_XML.getValue()) {
			type = TRANSPORT_XML;
		} else if (value == TRANSPORT_JSON.getValue()) {
			type = TRANSPORT_JSON;
		} else if (value == TRANSPORT_PLIST.getValue()) {
			type = TRANSPORT_PLIST;
		} else if (value == TRANSPORT_BYTECODE.getValue()) {
			type = TRANSPORT_BYTECODE;
		}
		return type;
	}
}